<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c"   uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s"   uri="/struts-tags"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<sec:authorize access="isAuthenticated()" >
	<s:set var="webAuth" value="true"/>
</sec:authorize>
<sec:authentication var="principal" property="principal" />
<script type="text/javascript">
	
	function cancelAction() {
	}
	
	function submitAction() {
		$("#changePasswordForm").submit();
	}
	
	var PASSWORD_REQUIRED		 = '<br>Required!';
	var PASSWORD_LEN_MIN		 = '<br>At least 6 chars';
	var PASSWORD_REPASS_THE_SAME = '<br>Must be the same new password';
	$(document).ready(function() {
		
		// validate signup form on keyup and submit
		$("#changePasswordForm").validate({
			rules: {
				"userInfo.passwordCur": {
					required: true,
					minlength: 6
				},
				"userInfo.passwordNew": {
					required: true,
					minlength: 6
				},
				"userInfo.passwordVer": {
					required: true,
					minlength: 6,
					equalTo: "#changePasswordForm_passwordNew"
				}
			},
			messages: {
				"userInfo.passwordCur": {
					required: PASSWORD_REQUIRED,
					minlength: PASSWORD_LEN_MIN
				},
				"userInfo.passwordNew": {
					required: PASSWORD_REQUIRED,
					minlength: PASSWORD_LEN_MIN
				},
				"userInfo.passwordVer": {
					required: PASSWORD_REQUIRED,
					minlength: PASSWORD_LEN_MIN,
					equalTo: PASSWORD_REPASS_THE_SAME
				}
			}
		});

	});
</script>

<h2>Password Change Center</h2>

<form name="changePasswordForm" id="changePasswordForm" action='<s:url action="/changepwd"/>' method="post">
	<table align="center" border=0 width = 55%>
		<tr>
			<td colspan="2">
				<font color="red"><s:property value="errorMessage"/></font>
			</td>
		</tr>
		<tr>
			<td align="left">Login ID : 		</td>
			<td>   	 <s:if test="%{webAuth}">${principal.username}</s:if></td>
        </tr>
		<tr>
			<td align="left">Old Password :	</td>
			<td><input type="password" name="userInfo.passwordCur" value="" size=20 maxlength="10" tabindex="1"></td>
		</tr>
		<tr>
			<td align="left">New Password :	</td>
			<td><input type="password" name="userInfo.passwordNew"  value="" size=20 maxlength="10" tabindex="2" id="changePasswordForm_passwordNew"></td>
		</tr>
		<tr>
			<td align="left">Confirm Password :</td>
			<td><input type="password" name="userInfo.passwordVer" value="" size=20 maxlength="10" tabindex="3"></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td><br/>
				<a href="#" class="btnlogin" onclick="submitAction();"  tabindex="5">Submit</a>
				<a href="#" class="btnlogin" onclick="cancelAction();"  tabindex="5">Cancel</a>
			</td>
		</tr>
  	</table>

</form>
